package com.neoCalf.neoAuth.service.impl;

import com.neoCalf.neoAuth.service.AuthService;
import com.neoCalf.neoCommon.entity.UserInfo;
import com.neoCalf.neoCommon.enums.RoleEnum;
import com.neoCalf.neoCommon.exception.AuthException;
import com.neoCalf.neoCommon.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
 * @author 小牛
 * @version 1.0
 * @description TODO
 * @date 2025/4/7 18:27
 */
@Service(value = "authService")
public class AuthServiceImpl implements AuthService {
    @Autowired
    private JwtUtil<Long> jwtUtil;

    @Override
    public String createToken(UserInfo userInfo) {
        return jwtUtil.generateJwtToken(userInfo);
    }

    @Override
    public Map<String, Object> validateToken(String token, String role) throws AuthException {
        return jwtUtil.checkTokenToClaims(token, RoleEnum.getByType(role));
    }
}
